<div class="pageHeader">
    <div class="searchBar">
    <input type="hidden" name="flowNodeId" value="<#if flowNode??>${flowNode.id!''}</#if>" />
    <table class="searchContent pageFormContent">
        <tbody>
        <#if flowNode.type=="userTask">
        <tr>
            <td><@label key='chooseAssignee.C,colon'>选择执行人：</@label></td>
            <td><input type="text" name="userText" id="userLookUp.userText" class="look" postField="userText" suggestFields="userCode,userText" 
                    suggestUrl="${rc.getContextPath()}/manage/user/userSuggest" lookupGroup="userLookUp" callback="flowNodeJs._addFlowNodeUser">
                <a class="btnLook" href="${rc.getContextPath()}/manage/user/flowNodeUserLookUp" rel="flowNodeUser_dialog" callback="flowNodeJs._addFlowNodeUser" lookupGroup="userLookUp" ></a>    
                <input type="hidden" name="userCode" id="userLookUp.userCode" >
            </td>
            <td id="flowNodeUser"></td>
        </tr>
         <tr>
            <td><@label key='yes.C,startFlowUser.C,colon'>发起人：</@label></td>
            <td>
                <input type="checkbox" name="isStartor" value="1" title="处理人为流程发起人的时候勾选此节点" />
            </td>
        </tr>
        <tr>
            <td><@label key='chooseRoles.C,colon'>选择角色：</@label></td>
            <td><input type="text" name="roleValue" id="flowNodeRoleLookup.roleText"  class="look" postField="roleText" suggestFields="roleCode,roleText" 
                    suggestUrl="${rc.getContextPath()}/manage/role/flowNodeRoleSuggest" lookupGroup="flowNodeRoleLookup" callback="flowNodeJs._addFlowNodeRole"/>
                <a class="btnLook" href="${rc.getContextPath()}/manage/role/flowNodeRoleLookUp" rel="flowNodeRole_dialog" callback="flowNodeJs._addFlowNodeRole" lookupGroup="flowNodeRoleLookup" ></a>    
                <input type="hidden" name="roleValue" id="flowNodeRoleLookup.roleCode" >
            </td>
            <td id="flowNodeRole"></td>
        </tr>
        <tr>
            <td><@label key='chooseGroups.C,colon'>选择组织：</@label></td>
            <td><input type="text"  id="flowNodeOrgLookup.organizationText" class="look" readonly="readonly">
                <a class="btnLook" href="${rc.getContextPath()}/manage/org/flowNodeOrgLookUp" width="640" height="500" rel="flowNodeOrg_dialog" lookupGroup="flowNodeOrgLookup" ></a>    
                <input type="hidden" name="orgValue" id="flowNodeOrgLookup.organizationCode" >
            </td>
        </tr>
        </#if> 
        <tr>
            <td><@label key='form.C,colon'>表单：</@label></td>
            <td><input type="text"  id="flowNodeFormLookup.screenText" class="look" value="${flowNode.formText!''}" readonly="readonly">
                <a class="btnLook" href="${rc.getContextPath()}/manage/screen/screenLookUp" width="640" height="500" rel="flowNodeForm_dialog" lookupGroup="flowNodeFormLookup" ></a>    
                <input type="hidden" name="formKey" value="${flowNode.formKey!''}" id="flowNodeFormLookup.screenCode" >
            </td>
            <td><div class="buttonActive" onclick="flowNodeJs._saveFlowNodeUser();"><div class="buttonContent"><button type="button"><@label key="save.B">保存</@label></button></div></div></td>
        </tr>
    </tbody>
    </table>
    </div>
</div>
<#if flowNode.type=="userTask">
<div class="pageContent">
    <table class="table canopration" width="100%" layoutH="135" id="flowNodeUserTabel">
        <thead>
            <tr>
                <th width="100" ><@label key='flowNodeName.C'>节点名称</@label></th>
                <th width="100" ><@label key='flowNodeUserType.C'>用户类型</@label></th>
                <th width="200" ><@label key='flowNodeUserValue.C'>用户表达式</@label></th>
                <th width="200" ><@label key='flowNodeUserText.C'>用户描述</@label></th>
                <th width="50"><@label key="opera.C">操作</@label></th>
            </tr>
        </thead>
        <tbody>
            <#if flowNode??>
                <#if flowNode.users??>
                    <#list flowNode.users as user>
                        <tr id="${user.id!''}">
                        <td>${flowNode.name!''}</td>
                        <td>${user.type!''}</td>
                        <td>${user.value!''}</td>
                        <td><#if user.assigneeName?? &&  user.assigneeName!=''>${user.assigneeName!''}<#else><#if user.groups?? &&  user.groups!=''>${user.groups!''}<#else>${user.roles!''}</#if></#if></td>
                        <td><a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="flowNodeJs._delFlowNodeUser(${user.id!''});"><@label key="delete.B">删除</@label></a></td>
                        </tr>
                    </#list>
                </#if>
            </#if>
        </tbody>
    </table>
</div>
</#if>

<script type="text/javascript">
    var flowNodeJs = {
            formKey : "${flowNode.formKey!''}",
            _addFlowNodeUser : function() {
                var userCode = $("input#userLookUp\\.userCode").val();
                var userText = $("input#userLookUp\\.userText").val();
                var label = $("label#user_"+userCode).html();
                if(!label && userCode != ""){
                    $("td#flowNodeUser").append("<label id='user_"+userCode+"'><input type='checkbox' onclick='$(this).parent().remove();' name='userValue' checked value='"+userCode+"' />"+userText+"</label>");
                }
                $("input#userLookUp\\.userCode").val("");
                $("input#userLookUp\\.userText").val("");
            },
            
            _addFlowNodeRole : function() {
                var roleCode = $("input#flowNodeRoleLookup\\.roleCode").val();
                var roleText = $("input#flowNodeRoleLookup\\.roleText").val();
                var label = $("label#role_"+roleCode).html();
                if(!label && roleCode!="")
                    $("td#flowNodeRole").append("<label id='role_"+roleCode+"'><input type='checkbox' name='roleValue' onclick='$(this).parent().remove();' checked value='"+roleCode+"' />"+roleText+"</label>");
                
                $("input#flowNodeRoleLookup\\.roleCode").val("");
                $("input#flowNodeRoleLookup\\.roleText").val("");
            },

            _delFlowNodeUser : function(_id) {
                var evt = window.event || arguments.callee.caller.arguments[0];
                evt.stopPropagation();
                if(_id){
                    alertMsg.confirm("<@label key='delete_sure.D'>确定删除</@label>？",{
                        okCall:function(){
                            $.DWZajax({
                                url:hostUrl +"/flowNode/delFlowNodeUser",
                                data:{'id':_id},
                                callback:function(data){
                                    $("#flowNodeUserTabel .gridTbody", $.pdialog.getCurrent()).find('tr#'+_id).remove();
                                }
                            });
                        }
                    });
                }
            },
            
            _saveFlowNodeUser : function() {
                var saveFlag = false;
                var users = [];
                var roles = [];
                $(":checkbox", $.pdialog.getCurrent()).each(function(i, n){
                    var name = $(this).attr("name");
                    var value = $(this).val();
                    if(name && name=="userValue"){
                        users.push(value);
                    }else if(name && name=="roleValue"){
                        roles.push(value);
                    }
                });
                var orgs = $("input#flowNodeOrgLookup\\.organizationCode").val();
                var flowNodeId = $("input[name='flowNodeId']").val();
                if(!flowNodeId || flowNodeId == ""){
                    alertMsg.error("请选择一个用户节点进行分配!");
                    return;
                }
                    
                var postData = {};
                if(users.length>0){
                    postData["users"] = users.join(",");
                    saveFlag = true;
                }
                if(roles.length>0){
                    postData["roles"] = roles.join(",");
                    saveFlag =  true;
                }
                if(orgs && orgs!=""){
                    postData["orgs"] = orgs;
                    saveFlag = true;
                }
                var formKey = $("input[name='formKey']", $.pdialog.getCurrent()).val();
                if(formKey && formKey != "" && formKey != flowNodeJs.formKey){
                    postData["formKey"] = formKey;
                    saveFlag = true;
                }
                var isStartor = $("input[name='isStartor']", $.pdialog.getCurrent()).is(':checked');
                if(isStartor){
                	postData["isStartor"] = $("input[name='isStartor']", $.pdialog.getCurrent()).val();
                    saveFlag = true;
                }
                if(!saveFlag){
                	alertMsg.info("保存成功!");
                	return;
                }
                postData["flowNodeId"] = flowNodeId;
                
                $.DWZajax({
                    url:hostUrl +"/flowNode/saveFlowNodeUser",
                    data:postData,
                    callback:function(data){
                        $.pdialog.reload(hostUrl +"/flowNode/reloadFlowNodeUser?flowNodeId="+flowNodeId);
                    }
                });
                
            }
            
    }
</script>